<html>
<head><meta charset="utf-8"><title>ast::P AsRef? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html">ast::P AsRef?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227339019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227339019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227339019">(Feb 22 2021 at 21:19)</a>:</h4>
<p>I was surprised to find <code>rustc_ast::ast::P</code> does not impl <code>AsRef</code>. Any reason not to add this?</p>



<a name="227339287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227339287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227339287">(Feb 22 2021 at 21:21)</a>:</h4>
<p>Would it be useful?</p>



<a name="227339594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227339594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227339594">(Feb 22 2021 at 21:23)</a>:</h4>
<p>Well I tried to generify some code in clippy</p>



<a name="227339755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227339755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227339755">(Feb 22 2021 at 21:24)</a>:</h4>
<p>we have a bunch of code like <code>all_eq_by(fns_a, fns_b, |a, b| eq_fn)</code> which could be <code>all_eq_by(fns_a, fns_b, eq_fn)</code></p>



<a name="227343106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227343106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227343106">(Feb 22 2021 at 21:48)</a>:</h4>
<p>Hmm just realized AsRef is not implemented T-&gt;T so it's not generic enough..</p>



<a name="227350943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227350943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227350943">(Feb 22 2021 at 22:34)</a>:</h4>
<p>You probably want Borrow, not AsRef</p>



<a name="227351827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227351827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227351827">(Feb 22 2021 at 22:40)</a>:</h4>
<p>I'm not using PartialEq though</p>



<a name="227351907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227351907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227351907">(Feb 22 2021 at 22:41)</a>:</h4>
<p>And I want it to work whether deref is needed or not. But that abstraction doesn't seem to exist for generic functions.</p>



<a name="227352370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/ast%3A%3AP%20AsRef%3F/near/227352370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Cameron Steffen <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/ast.3A.3AP.20AsRef.3F.html#227352370">(Feb 22 2021 at 22:45)</a>:</h4>
<p><code>I: IntoIterator, I::Item: MaybeDeref&lt;T&gt;</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>